#include <my/System/EventHandling.h>

namespace my {


    EventHandling::EventHandling() {

    }

    EventHandling::~EventHandling() {

    }


    void EventHandling::connect(const std::string& str, my::slot func) {
        _table.insert(std::pair<std::string, my::slot>(str, func));
    }

    void EventHandling::emit(const std::string& str) {
        std::pair<std::multimap<std::string, my::slot>::iterator, std::multimap<std::string, my::slot>::iterator> range;
        range = _table.equal_range(str);

        for(std::multimap<std::string, my::slot>::iterator it = range.first; it != range.second; ++it)
            (*it).second();
    }

    void EventHandling::disconnect(const std::string& signal) {
        std::pair<std::multimap<std::string, my::slot>::iterator, std::multimap<std::string, my::slot>::iterator> range;
        range = _table.equal_range(signal);

        for(std::multimap<std::string, my::slot>::iterator it = range.first; it != range.second; ++it)
            _table.erase(it);
    }

    void EventHandling::clear() {
        _table.clear();
    }


}
